package commands.supplier
{
	import cultu.community.message.Community;
	import cultu.customer.message.Customer;
	import cultu.supplier.message.ProductCriteria;
	import cultu.supplier.service.ProductService;
	
	import model.Model;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import wizeoo.commands.WIZRemoteCall;
	
	public class FindAssociationsCmd extends WIZRemoteCall
	{
		/**Référence au model*/
		private var mod:Model = Model.getInstance();
		
		
		public function FindAssociationsCmd(pCallback:Function=null)
		{
			super(pCallback);
		}
		
		override public function wizExecute():void
		{
			var ps:ProductService = new ProductService();
			var pc:ProductCriteria = new ProductCriteria();
			pc.maxResult = 10;
			
			ps.addEventListener(ResultEvent.RESULT,result,false,0,true);
			ps.addEventListener(FaultEvent.FAULT,fault,false,0,true);
			
			var customer:Customer = null;
			
			var community:Community = null;
			
			if(mod.connectedUser)
				customer = mod.connectedUser.customer;
			
			if(mod.selectedCommunity)
				community = mod.selectedCommunity.srcCommunity;
			
			ps.getAssociations(customer,community,pc);
		}
		
		override protected function wizResult(data:Object):void
		{
			if(data && data.result)
			{
				mod.currentAssociations = data.result as ArrayCollection;
			}
		}
		
		override protected function wizFault(info:Object):void
		{
			trace('unable to get associations');	
		}
	}
}